package com.liry.security.controller;

import com.liry.security.service.AuthService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ALI
 * @since 2023/5/31
 */
@RestController
public class LoginController {

    @Autowired
    private AuthService authService;

    @GetMapping("/index.html")
    public String index() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication);
        return "index";
    }

    @GetMapping("/main.html")
    public String main() {
        return "main";
    }

    @GetMapping("/test/1")
    public String test() {
        return "test";
    }

    @GetMapping("/login/captcha")
    public String captcha(HttpServletRequest request, HttpServletResponse response) {
        authService.captcha(request, response);
        return null;
    }

    @GetMapping("/login/captcha/valid")
    public Boolean validCaptcha(HttpServletRequest request) {
        return authService.validCaptcha(request);
    }

}
